<?php

/**
 * Add Custom Class in tinyMce editor
 * @package Wordpress
 * @subpackage wp-dev
 */
function wpdev_add_advanced_class($settings) {
	
	$classes = array('Custom Class=custom');
	
	$settings['theme_advanced_styles'] = implode($classes, ";");
	$settings['theme_advanced_buttons2'] = 'styleselect,'.$settings['theme_advanced_buttons2'];
	
	return $settings;
}
add_action('tiny_mce_before_init', 'wpdev_add_advanced_class');

/**
 * Arquivo que Contem todas as actions do site
 * @package Wordpress
 * @subpackage wp-dev
 */

function wpdev_create_rewrite_rule() {
	global $wp_rewrite;

	$rewrite = array(
		'(custom-action)/(.*)' => 'index.php?custom_action='.$wp_rewrite->preg_index(2)
	);
	
	$wp_rewrite->rules = $rewrite + $wp_rewrite->rules;
	
	return $wp_rewrite->rules;
}
add_action('generate_rewrite_rules', "wpdev_create_rewrite_rule");
add_action('admin_init', 'flush_rewrite_rules');


function wpdev_set_action(){
	global $wp_query, $wp_rewrite;
	
	require_once(TEMPLATEPATH."/dev/library/controller/action.class.php");
	
	if ( isset($wp_query->query_vars['custom_action']) && class_exists('Action') ) {
		$params = explode("/", $wp_query->query_vars['custom_action']);
		
		$method = array_shift($params);
		$method = str_replace('-', "_", $method);
		
		if(method_exists($action, $method)){
			
			$action->$method($params);
			
			exit();
		}
	}
}
add_action('wpdev_template_redirect', 'set_action');

/*
 * Setup custom posts types
 */
function wpdev_register_custom_types() {
	$default_options = array(
		'public' => true,
		'show_ui' => true,
		'capability_type' => 'post',
		'hierarchical' => true,
		'rewrite' => true,
		'supports' => array('title', 'excerpt', 'editor', 'thumbnail', 'page-attributes')
	);
	
	$customArgs = array(
		'label' => __('Custom Post', 'interface'),
		'singular_label' => __('Custom Post', 'interface')
	);
	
	register_post_type( 'custom-post' , $default_options + $customArgs);
	
	$labels = array(
		'name' => __("Custom Tax", "inteface"),
		'singular_name' => __("Custom Tax", "inteface"),
		'search_items' => __("Search Custom Tax", "inteface"),
		'all_items' => __("All Custom Tax", "inteface"),
		'parent_item' => __("Parent Custom Tax", "inteface"),
		'parent_item_colon' => __("Parent Custom Tax", "inteface"),
		'edit_item' => __("Edit Custom Tax", "inteface"), 
		'update_item' => __("Update Custom Tax", "inteface"),
		'add_new_item' => __("Add New Custom Tax", "inteface"),
		'new_item_name' => __("New Project Custom Tax", "inteface")
	);
	
	register_taxonomy('custom-tax',array("custom-post"), array(
		'hierarchical' => true,
		'labels' => $labels,
		'show_ui' => true,
		'query_var' => true,
		'rewrite' => array('slug' => 'custom-tax')
	));
}
add_action('init', 'wpdev_register_custom_types');